package com.yanqu.road.server.manager.cricket;

import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.manager.cricket.entity.DbCricketHotBattleLog;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

public class CricketDbData {
    private final List<DbCricketHotBattleLog> dbCricketHotBattleLogList = new ArrayList<>();

    private final AtomicLong battleLogIdAutoIncrease = new AtomicLong();

    public void addDbCricketHotBattleLog(DbCricketHotBattleLog dbCricketHotBattleLog) {
        List<Integer> list = StringUtils.stringToIntegerList(GameConfig.CRICKET_FIGHT_REPORT_HOT_VALUE_LIMIT, "\\|");
        synchronized (dbCricketHotBattleLogList) {
            long battleLogId = battleLogIdAutoIncrease.incrementAndGet();
            dbCricketHotBattleLog.setBattleLogId(battleLogId);
            dbCricketHotBattleLogList.add(dbCricketHotBattleLog);
            if (dbCricketHotBattleLogList.size() > list.get(2)) {
                dbCricketHotBattleLogList.remove(0);
            }
        }
    }

    public List<DbCricketHotBattleLog> getDbCricketHotBattleLogList() {
        return dbCricketHotBattleLogList;
    }

    public AtomicLong getBattleLogIdAutoIncrease() {
        return battleLogIdAutoIncrease;
    }
}
